import java.util.Arrays;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-02-03
 * Time:17:05
 */
public class myStack {
    public int[] elem;
    public int usedsize;

    public myStack(){
        this.elem = new int[5];
    }

    public void push(int val){
        if(isFull()){
            //扩容
            this.elem = Arrays.copyOf(this.elem,2*this.elem.length);
        }
        this.elem[this.usedsize] = val;
        this.usedsize++;
    }

    public boolean isFull(){
        return this.usedsize == this.elem.length;
    }

    public int pop(){
        if(isEmpty()){
            throw new RuntimeException("栈为空！");
        }
        int oldval = this.elem[usedsize-1];
        this.usedsize--;
        return oldval;
    }

    public int peek(){
        if(isEmpty()){
            throw new RuntimeException("栈为空！");
        }
        return this.elem[usedsize-1];
    }

    public boolean isEmpty(){
        return this.usedsize == 0;
    }
}
